﻿@model OrderPlaceModel

@{
    Layout = "~/Views/Shared/_ContentLayout.cshtml";
}
@{
    var viewModel = Model ?? new OrderPlaceModel();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
}
<form id="S_Form" action="@Url.Action("doSave", "OrderPlace")" method="post" class="definewidth m20">
    <input type="hidden" value="@viewModel.view_OrderPlace.seq_id" name="seq_id" />
    <input type="hidden" value="@viewModel.view_OrderPlace.uid" name="uid" />
    <input type="hidden" value="@viewModel.view_OrderPlace.goods_amount" id="goods_amount" name="goods_amount" />

    <h3>物料信息</h3>
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="15%">料号</td>
            <td width="35%">@viewModel.views_Goods.MPN <a href="@Url.Action("detailInfo","product",new { id = viewModel.views_Goods.goods_id })">查看物料详情</a></td>
            <td width="15%">品牌</td>
            <td width="35%">
                @viewModel.views_Goods.brand_name
            </td>
        </tr>
        <tr>
            <td width="15%">分类</td>
            <td width="35%">
                @viewModel.views_Goods.category_name
            </td>
            <td>供应商</td>
            <td>
                @viewModel.views_Goods.supplier_name
                @*@if (!string.IsNullOrWhiteSpace(viewModel.views_Goods.material_source_name))*@
                @*{*@

                <p>物料来源：@viewModel.views_Goods.material_source_name</p>
                @*}*@
            </td>
        </tr>
        <tr>
            <td>库存数量</td>
            <td>@viewModel.views_Goods.stock_amount @viewModel.views_Goods.goods_unit </td>
            <td>最小订购量<em></em></td>
            <td>@viewModel.views_Goods.min_amount @viewModel.views_Goods.goods_unit</td>
        </tr>
        <tr>
            <td>DC号</td>
            <td>@viewModel.views_Goods.DCN</td>
            <td>库存日期</td>
            <td>@viewModel.views_Goods.stock_date</td>
        </tr>
        <tr>
            <td>货期</td>
            <td>@viewModel.views_Goods.DDD</td>
            <td>预热结束时间<em></em></td>
            <td>

                @viewModel.views_Goods.end_time.ToString(1)
                @if (viewModel.views_Goods.end_time < DateTime.Now)
                {
                    <info class="gray">已结束</info>
                }
                else
                {
                    <info class="red">剩余：@DateTimeHelper.DateDiffStr(DateInterval.Minute, DateTime.Now, viewModel.views_Goods.end_time)</info>
                }

            </td>

        </tr>
        <tr>
            <td>上架时间</td>
            <td>@viewModel.views_Goods.with_up_time.ToString(1)</td>
            <td>市场价格</td>
            <td>@viewModel.views_Goods.market_price</td>
        </tr>
        <tr>
            <td>币种</td>
            <td>
                @switch (viewModel.views_Goods.currency_type)
                {
                    case 0:
                        @:<div class="">人民币</div>
                        break;
                    case 1:
                        @:<div class="red">美金</div>
                        break;
                }
            </td>
            <td>商品描述</td>
            <td>@viewModel.views_Goods.product_desc</td>
        </tr>
        <tr>
            <td>商品图片</td>
            <td colspan="3" id="uploadImg">
                @{
                    var aDZ_GoodsIMGs = dbcontext.ADZ_GoodsIMG.Where(t => t.goods_id == viewModel.views_Goods.goods_id).OrderBy(t => t.sort_NO).ToList();
                    if (aDZ_GoodsIMGs.Any())
                    {
                        for (int index = 0; index < aDZ_GoodsIMGs.Count; index++)
                        {
                            var item = aDZ_GoodsIMGs[index];

                            <a href="javascript:void(0)" onclick="showimg('@ImageFileBiz.GetImg(item.img_url)')"> <img src="@ImageFileBiz.GetImg(item.img_url, "small")" alt=""></a>
                        }
                    }
                }
            </td>
        </tr>
    </table>
    <h3>预定信息</h3>
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="15%">会员</td>
            <td width="35%">
                手机号： @viewModel.view_OrderPlace.account_mobile 昵称：@viewModel.view_OrderPlace.member_name <a href="@Url.Action("DefailInfo","Account",new { uid = viewModel.view_OrderPlace.uid })">查看用户详情</a>
            </td>

            <td width="15%">报价状态</td>
            <td width="35%">
                @(MyEnumHelper.GetEnumItemDescription<PlaceStatus>(viewModel.view_OrderPlace.place_status))
            </td>
        </tr>
        <tr>
            <td>报价时间</td>
            <td>@viewModel.view_OrderPlace.update_time.ToString(1)</td>
            <td>是否有效报价</td>
            <td>
                @if (viewModel.view_OrderPlace.is_del == 0)
                {
                    <div class="green">有效报价</div>
                }
                else
                {
                    <div class="red">失效报价</div>
                }
            </td>
        </tr>
        <tr>
            <td width="10%">报价信息</td>
            <td>报价单价：@viewModel.view_OrderPlace.place_price /@viewModel.views_Goods.goods_unit &nbsp;报价数量：@viewModel.view_OrderPlace.goods_amount @viewModel.views_Goods.goods_unit  &nbsp;报价总价：@((viewModel.view_OrderPlace.place_price * viewModel.view_OrderPlace.goods_amount).Value.ToString("f2"))</td>
            <td>是否中标<em></em></td>
            <td>
                @if (viewModel.view_OrderPlace.is_hit == 1)
                {
                    <div class="green">已中标 中标时间：@viewModel.view_OrderPlace.hit_time.ToString(1)</div>
                }
                else
                {
                    <info>未中标</info>
                    @*if (viewModel.view_OrderPlace.is_del == 0 && viewModel.view_OrderPlace.place_status == (int)PlaceStatus.Placeing)
                        {
                            <button type="button" class="btn btn-primary" id="btn_setHit">设为中标</button>
                        }*@

                }
            </td>
        </tr>
        @if (viewModel.view_OrderPlace.is_hit == 1 && viewModel.view_Order != null)
        {
            var aDZ_OrderDetails = dbcontext.ADZ_OrderDetails.FirstOrDefault(t => t.order_id == viewModel.view_Order.order_id);
            if (aDZ_OrderDetails != null)
            {
                <tr style="font-weight:bold;">
                    <td>中标信息</td>
                    <td colspan="3">
                        中标单价：@aDZ_OrderDetails.price /@viewModel.views_Goods.goods_unit &nbsp;中标数量：@(aDZ_OrderDetails.amount) @(viewModel.views_Goods.goods_unit) &nbsp;<info class="red">中标总价：@((aDZ_OrderDetails.price * viewModel.view_OrderPlace.goods_amount).Value.ToString("f2"))</info>
                    </td>
                </tr>
            }
        }
    </table>
    <h3>订单信息</h3>
    @if (viewModel.view_Order == null)
    {
        <div id="div_neworder">
            <b>还未生成订单信息</b>
            @if (viewModel.views_Goods.currency_type.HasValue && viewModel.views_Goods.currency_type != 0)
            {
                <info class="red">非人民币业务，无法下单</info>
            }
            @if (viewModel.view_OrderPlace.is_del == 0 && viewModel.view_OrderPlace.place_status == (int)PlaceStatus.Placeing)
            {
                <button type="button" class="btn btn-primary" id="btn_showsetHitOrder">设为中标并下单</button>
            }
        </div>
        var aDZ_UserAddresses = dbcontext.ADZ_UserAddress.Where(t => t.uid == viewModel.view_OrderPlace.uid).OrderByDescending(t => t.is_default).ToList();
        <table style="display:none;" class="table table-bordered table-hover definewidth m10" id="tb_setHitOrder">
            <tr>
                <td colspan="5"><b>请选择收货地址或使用新地址： </b></td>
            </tr>
            @if (aDZ_UserAddresses.Any())
            {
                foreach (var item in aDZ_UserAddresses)
                {
                    <tr>
                        <td width="5%">
                            <input type="radio" name="checkaddress" value="@item.seq_id" @(item.is_default == 1 ? "checked" : "") />
                            <info class="red">@((item.is_default == 1) ? "默认地址" : "")</info>
                        </td>
                        <td width="20%">收货人姓名：@item.receiver</td>
                        <td width="20%">收货人手机号：@item.receiver_telephone</td>
                        <td width="20%">城市：@item.city_name</td>
                        <td width="35%">地址：@item.address</td>
                    </tr>
                }
            }
            <tr>
                <td width="5%"><input type="radio" name="checkaddress" value="0" />使用新地址</td>
                <td width="20%">
                    收货人姓名：<em>*</em><input type="text" name="newCreateAddress.new_receiver" id="newCreateAddress.new_receiver" maxlength="100" value="" />
                </td>
                <td width="20%">收货人手机号：<em>*</em><input type="text" name="newCreateAddress.new_receiver_telephone" id="newCreateAddress.new_receiver_telephone" maxlength="100" value="" /></td>
                <td width="20%">
                    城市：<em>*</em>
                    @{
                        //构建默认对象
                        var CityInfo1 = new CityInfoViewModel
                        {
                            DivID = "cityidaa1",
                            CityIDFormName = "newCreateAddress.new_city_id",
                            CityNameFormName = "newCreateAddress.new_city_name",
                            ShowDeep = 3
                        };
                    }
                    @{Html.RenderPartial(Url.Content("~/Views/Common/CitySelect.cshtml"), CityInfo1);}
                </td>
                <td width="35%">地址：<em>*</em><input type="text" name="newCreateAddress.new_address" style="width:90%" id="newCreateAddress.new_address" maxlength="100" value="" /></td>
            </tr>
            <tr>
                <td colspan="5">下单单价：<input type="text" name="place_price" id="place_price" maxlength="100" value="@viewModel.view_OrderPlace.place_price" />  订购量：@viewModel.view_OrderPlace.goods_amount @viewModel.views_Goods.goods_unit 总价：¥ <info id="total_money" class="red">@((viewModel.view_OrderPlace.place_price * viewModel.view_OrderPlace.goods_amount).Value.ToString("f2"))</info> </td>
            </tr>
            <tr>
                <td colspan="5">备注：<textarea name="remark" style="width:80%;" maxlength="2500" placeholder="" cols="4"></textarea></td>
            </tr>
            <tr>
                <td colspan="5"><button type="button" class="btn btn-primary" id="btn_setHitOrder">生成订单</button> <span id="spMsg"></span> </td>
            </tr>
        </table>
    }
    else
    {
        <table class="table table-bordered table-hover definewidth m10">
            <tr>
                <td width="15%">订单号</td>
                <td width="35%">
                    @viewModel.view_Order.order_NO  <a href="@Url.Action("OrderMasterInfo","OrderMaster",new { id=viewModel.view_Order.order_id})">查看订单详情</a>
                </td>

                <td width="15%">订单金额</td>
                <td width="35%">
                    @viewModel.view_Order.total_money
                </td>
            </tr>
            <tr>
                <td>下单时间</td>
                <td>@viewModel.view_Order.create_time.ToString(1)</td>
                <td>订单状态</td>
                <td>
                    @(MyEnumHelper.GetEnumItemDescription<OrderStatus>(viewModel.view_Order.order_status))
                </td>
            </tr>
            <tr>
                <td>支付方式</td>
                <td>@(MyEnumHelper.GetEnumItemDescription<PayType>(viewModel.view_Order.pay_type))</td>
                <td>支付信息<em></em></td>
                <td>
                    @if (viewModel.view_Order.is_succ.Value == (int)PaySucc.Paid)
                    {
                        <div class="green">已支付 支付时间：@viewModel.view_Order.pay_succ_time.ToString(1)</div>
                    }
                    @if (viewModel.view_Order.is_succ.Value == (int)PaySucc.NotPay)
                    {
                        <span class="red">
                            未支付
                        </span>
                    }
                </td>
            </tr>
            <tr>
                <td class="tableleft">备注信息</td>
                <td colspan="3">@viewModel.view_Order.remark</td>
            </tr>
        </table>
    }


</form>
<script>
        var pro = '全国';
        var city = '全部';

        $("#city").citySelect();
        $("#city").citySelect({
            url: "../Css/assets/js/city.min.js",
            prov: pro, //省份
            city: city//城市
        });

        var cancelButton =
            {
                text: '取消',
                elCls: 'button',
                handler: function () {
                    this.close();
                }
            };
        reloadHandler = function () {
            window.location.reload();
        }

        BUI.use('bui/overlay', function (overlay) {
            $(function () {

                $("#place_price").on("input", function () {
                    $("#total_money").html((($("#place_price").val() * $("#goods_amount").val())).toFixed(2));
                });

            $("#btn_showsetHitOrder").click(function () {
                $("#div_neworder").hide();
                $("#tb_setHitOrder").show();
            });
            $("#btn_setHitOrder").click(function () {

                $("#S_Form").attr("action", "@Url.Action("setHitOrder", "OrderPlace")");

                var validator = $("#S_Form").validate({
                    errorLabelContainer: $("#errorContainer"),
                    errorElement: "span",
                    submitHandler: function (form) {
                        $("#S_Form").ajaxSubmit(function (result) {

                            ShowActionResult(result, function () { window.location.reload(); });
                        });
                    }
                });
                $("#S_Form").submit();
            });
            });
        });
</script>
